﻿namespace Borg.AddOn
{
    internal class CompositionPermissionHookChain : ICompositionPermissionHook
    {
        private readonly ICompositionPermissionHook[] _hooks;

        public CompositionPermissionHookChain(ICompositionPermissionHook[] hooks)
        {
            _hooks = hooks;
        }

        public bool CanCreate(ExtensionType extensionType, out LogArgs log)
        {
            foreach (ICompositionPermissionHook hook in _hooks)
                if (!hook.CanCreate(extensionType, out log))
                    return false;

            log = null;
            return true;
        }

        public bool CanPlug(Slot slot, Plug plug, out LogArgs log)
        {
            foreach (ICompositionPermissionHook hook in _hooks)
                if (!hook.CanPlug(slot, plug, out log))
                    return false;

            log = null;
            return true;
        }

        public bool CanTag(Slot slot, Plug plug, string tag, out LogArgs log)
        {
            foreach (ICompositionPermissionHook hook in _hooks)
                if (!hook.CanTag(slot, plug, tag, out log))
                    return false;

            log = null;
            return true;
        }

        public bool CanUnplug(Slot slot, Plug plug, out LogArgs log)
        {
            foreach (ICompositionPermissionHook hook in _hooks)
                if (!hook.CanUnplug(slot, plug, out log))
                    return false;

            log = null;
            return true;
        }

        public bool CanUntag(Slot slot, Plug plug, string tag, out LogArgs log)
        {
            foreach (ICompositionPermissionHook hook in _hooks)
                if (!hook.CanUntag(slot, plug, tag, out log))
                    return false;

            log = null;
            return true;
        }
    }
}

